var app = getApp();
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var pay = require('../../../services/pay.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      order_id: options.order_id
      // trainInfo: wx.getStorageSync("trainInfo"),
      // orderInfo: wx.getStorageSync("orderInfo")
    })
    this.getOrderInfo()
  },
  getOrderInfo: function(){
    var that = this;
    util.request(api.OrderDetail, { order_id: this.data.order_id }).then(res => {
      if (res.code == 200) {
        // wx.setStorageSync("orderInfo", res.data)
        that.setData({
          orderInfo: res.data.orderInfo,
          trainInfo: res.data.trainInfo
        })
      } else {
        util.showErrorToast('参数错误');
      }
    });
  },
  payOrder:function(){
    const orderId = this.data.orderInfo.order_id;
    pay.payOrder(parseInt(orderId)).then(res => {
      console.log(res);
      wx.redirectTo({
        url: '/pages/payment/result/index?status=success&order_id=' + orderId
      });
    }).catch(res => {
      wx.redirectTo({
        url: '/pages/payment/result/index?status=warn&order_id=' + orderId
      });
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})